package com.aliyun.messagemgt.web.controller;

import com.aliyun.messagemgt.application.service.MessageRecordService;
import com.aliyun.messagemgt.application.service.PushService;
import com.aliyun.messagemgt.common.dto.response.AjaxResult;
import com.aliyun.messagemgt.common.dto.response.ResultMap;
import com.aliyun.messagemgt.dto.msg.MessageRecordDTO;
import com.aliyun.messagemgt.dto.msg.MessageRecordQry;
import com.aliyun.messagemgt.dto.out.MsgPushResponseDTO;
import com.aliyun.messagemgt.dto.query.MessageRecordQueryDTO;
import com.aliyun.messagemgt.dto.query.MyMsgQueryDTO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 消息记录控制器
 * 
 * @author changcong
 *
 */
@Api(tags = "消息管理相关接口")
@RestController
public class MessageRecordController {

	@Autowired
	private MessageRecordService messageRecordService;
	@Autowired
	private PushService pushService;

	@PostMapping(value = "/message/list")
	@ResponseBody
	public Object list(@RequestBody MessageRecordQueryDTO messageRecordQueryDTO) {
		return messageRecordService.selectMessageRecord(messageRecordQueryDTO);
	}

	@PostMapping(value = "/message/page")
	@ResponseBody
	@ApiResponses({
			@ApiResponse(code = 200, message = "列表对象", response = MessageRecordDTO.class)
	})
	public ResultMap<PageInfo<MessageRecordDTO>> page(@RequestBody MessageRecordQry messageRecordQry) {
		return new ResultMap<>(messageRecordService.page(messageRecordQry));
	}

	/**
	 * 消息重发接口(用于消息发送失败的情况)
	 * @param msgId
	 * @return
	 */
	@GetMapping("/message/repush")
	@ResponseBody
	@ApiResponses({
			@ApiResponse(code = 200, message = "消息发送响应结果", response = MsgPushResponseDTO.class)
	})
	public ResultMap<MsgPushResponseDTO> msgRePush(@ApiParam("消息记录id")Long msgId) {
		return pushService.apiRePush(msgId);
	}

	@RequestMapping(value = "/message/list/ownerDept")
	@ResponseBody
	public Object messageListOwnerDept(@RequestBody MessageRecordQueryDTO messageRecordQueryDTO) {
		return AjaxResult.success(messageRecordService.messageListOwnerDept(messageRecordQueryDTO));
	}

	@RequestMapping(value = "/message/list/myMsgs")
	@ResponseBody
	public Object messageListMyMsgs(@RequestBody MyMsgQueryDTO myMsgQueryDTO) {
		return AjaxResult.success(messageRecordService.messageListMyMsgs(myMsgQueryDTO));
	}
}
